package base.java8.time;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.function.Consumer;

/**
 * 时间调整器
 *
 * @author 王霄
 * @date 2021/9/11 23:09
 */
public class TemporalAdjustersDemo {
    public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static void main(String[] args) {

        LocalDateTime now = LocalDateTime.now();
        //调整到下个周三
        System.out.println(now.with(TemporalAdjusters.next(DayOfWeek.WEDNESDAY)));
        //调整到下个周二
        System.out.println(now.with(TemporalAdjusters.next(DayOfWeek.of(2))));
        //调整到这个月第一天
        System.out.println(now.with(TemporalAdjusters.firstDayOfMonth()));
        //调整到这个月最后一天
        System.out.println(now.with(TemporalAdjusters.lastDayOfMonth()));
        //调整到下个月的第一天
        System.out.println(now.with(TemporalAdjusters.firstDayOfNextMonth()));
        //调整到去年的最后一天
        System.out.println(now.with(TemporalAdjusters.lastDayOfYear()));
        //调整到明年第一天
        System.out.println(now.with(TemporalAdjusters.firstDayOfNextYear()));

    }
}
